//This do file can be used on the 2016 ANES dataset downloaded directly from the ANES website. The purpose of this do file is to clean and rename variables of interest and drop unnecessary variables in order to merge the 2020 and 2016 data files.

*Before running this file, download the dataset directly from ANES, and read it into Stata

generate year =2016 

*white identity questions
rename V162327 wid1
rename V162316 wid2
rename V162317 wid3

*demos
rename V161126 ideology 
rename V161158x pid7

rename V161267x age

rename V161342 gender
rename V161310x race
rename V161245 religattend
rename V161265x religion

*voting behavior 
generate pres2012vote = 1 if V161006 == 2
replace pres2012vote = 2 if V161006 == 1

label define pres2012vote1 1 "Romney" 2 "Obama" 
label values pres2012vote pres2012vote1

generate pres2016vote = 1 if V161027 == 2
replace pres2016vote = 2 if V161027 == 1

label define pres2016vote1 1 "Trump" 2 "Clinton" 
label values pres2016vote pres2016vote1

*income
generate income = 1 if V161361x == 1 | V161361x ==2
replace income = 2 if V161361x == 3 | V161361x ==4
replace income = 3 if V161361x == 5 | V161361x ==6
replace income = 4 if V161361x == 7 | V161361x ==8
replace income = 5 if V161361x == 9 | V161361x ==10
replace income = 6 if V161361x == 11
replace income = 7 if V161361x == 12
replace income = 8 if V161361x == 13
replace income = 9 if V161361x == 14
replace income = 10 if V161361x == 15 | V161361x == 16
replace income = 11 if V161361x == 17
replace income = 12 if V161361x == 18
replace income = 13 if V161361x == 19
replace income = 14 if V161361x == 20
replace income = 15 if V161361x == 21
replace income = 16 if V161361x == 22
replace income = 17 if V161361x == 23
replace income = 18 if V161361x == 24
replace income = 19 if V161361x == 25
replace income = 20 if V161361x == 26
replace income = 21 if V161361x == 27
replace income = 22 if V161361x == 28

*education 
generate edu = 1 if V161270 <9
replace edu = 2 if V161270 ==9
replace edu = 3 if V161270 == 10 | V161270 == 11 | V161270 ==12
replace edu = 4 if V161270 == 13 
replace edu = 5 if V161270 >13
drop if V161270 == -9 | V161270 ==90 | V161270 ==95
tab edu

//Issue Indexes

*nationalism 
rename V162271 nationalism1
rename V162272 nationalism2
rename V162273 nationalism3
rename V162274 nationalism4 

*racial resentment questions 
rename V162211 rr1
rename V162212 rr2
rename V162213 rr3
rename V162214 rr4

*immigration 
rename V161197 immigration1
rename V161194x immigration2
rename V161195x immigration3
rename V161196x immigration4

*women
rename V162229x women1
rename V162230x women2
rename V162232 women3
rename V162233 women4

*climate
rename V161221 climate1
rename V161225x climate2

*lgbtq+
rename V161227x lgbtq1
rename V161228x lgbtq2
rename V161229x lgbtq3
rename V161230 lgbtq4

*medical insurance
rename V161184 medinsur

*abortion
rename V161232 abortion

//Generate Operational Ideology

*death penalty
generate deathpen = 1 if V161233x == 1 | V161233x == 2
replace deathpen = -1 if V161233x == 3 | V161233x == 4

*gov make it more difficult to buy a gun
generate gunpurchase = 1 if V161187 == 2
replace gunpurchase = -1 if V161187 == 1
replace gunpurchase = 0 if V161187 == 3

*federal budget spending on welfare
generate welfarespend = 1 if V161209 == 2
replace welfarespend = -1 if V161209 == 1
replace welfarespend = 0 if V161209 == 3

*millionare tax
generate milltax = 1 if V162140 == 2
replace milltax = -1 if V162140 == 1
replace milltax = 0 if V162140 == 3

*treatment 
rename V162318 treat1
rename V162320 treat2

*gov spending for healthcare
generate healthspend = 1 if V162193x == 7 | V162193x == 6 | V162193x == 5
replace healthspend = -1 if V162193x == 1 | V162193x == 2 | V162193x == 3
replace healthspend = 0 if V162193x == 4

keep year wid1 wid2 wid3 ideology pid7 age gender race religattend religion pres2012vote pres2016vote income edu nationalism1 nationalism2 nationalism3 nationalism4 rr1 rr2 rr3 rr4 immigration1 immigration2 immigration3 immigration4 women1 women2 women3 women4 climate1 climate2 lgbtq1 lgbtq2 lgbtq3 lgbtq4 medinsur abortion deathpen gunpurchase welfarespend milltax treat1 treat2 healthspend 
















